package com.liu.entity;

import com.liu.common.ParentTemplate;
import com.liu.common.Template;


import java.util.ArrayList;
import java.util.List;

/**
 * @author Mr.Liu
 * @version 1.0
 * @date 2024/8/4 21:44
 */
public class EntityTemplate extends ParentTemplate implements Template {

    private static final  String SUFFIX = "Model";
    private static  final  String EXTENDS_PARENT = "CommonModel";


    public EntityTemplate() {
        super();
        this.setVarList(new ArrayList<Property>());
    }


    //构建出操作上下文返回方法
    public String toOperationContent(){
        StringBuffer sb = new StringBuffer();
        sb.append("    public String opeartionContent(){\n");
        sb.append("        return\n");
        List<Property> varList = this.getVarList();
        for(int ii = 0 ; ii < varList.size() ;ii++){
            sb.append("            ");
            if(ii == varList.size()-1){
                sb.append( "\""+varList.get(ii).getVarName()+"\"+"+varList.get(ii).getVarName() + "+\"}\";\n");
            }else if(ii == 0){
                sb.append("\"{"+varList.get(ii).getVarName()+"\"+"+varList.get(ii).getVarName() + "+\n");
            }else{
                sb.append("\""+"; "+varList.get(ii).getVarName()+"\"+"+varList.get(ii).getVarName()+ "+\n");
            }
        }
        sb.append("    }\n");
        return sb.toString();
    }


    @Override
    public String toTemplate(){
        StringBuffer sb = new StringBuffer();
        sb.append("package "+this.getPackageName()+".model;\n\n");
        sb.append("@Getter\n");
        sb.append("@Setter\n");
        sb.append("public class "+getClassName()+SUFFIX+" extends "+ EXTENDS_PARENT +" {\n\n");
        for (Property property : getVarList()) {
            sb.append("    private "+property.getVarType()+" "+property.getVarName()+";\n");
        }
        sb.append("\n\n");
        sb.append(toOperationContent());

        sb.append("\n}\n");


        return sb.toString();
    }





    @Override
    public String toString() {
        return "Entity{" +
                "className='" + getClassName() + '\'' +
                ", varList=" + getVarList() +
                '}';
    }



}
